package com.wwy.arithmetic.newsuanfa;

/**
 * @author 王伟羽
 * @program: arithmetictest
 * @description:
 * @create: 2025/03/31
 */

public class Zuichangqianzhui {

    /**
     * 输入：strs = ["flower","flow","flight"]
     * 输出："fl"
     * @param strs
     * @return
     */
    public String longestCommonPrefix(String[] strs) {
        if(strs.length==1){
            return strs[0];
        }
        String str = strs[0];
        String resp = "";
        for(int a=0;a<str.length();a++){
            String sub = str.substring(0,a+1);
            for (String s : strs) {
                if(!s.startsWith(sub)){
                    return resp;
                }
            }
            resp = sub;
        }
        return resp;
    }
}
